package xml;


import org.dom4j.*;
import org.dom4j.io.SAXReader;

import java.io.File;


/**
 * @Name : xml.WebsocketTest
 * @Description : 描述
 * Created by cyd on 2020-12-24 14:44:54
 */
public class XmlTest {
    public static void main(String[] args) throws  DocumentException {

        //2.将文档或节点的XML转化为字符串.
        SAXReader reader = new SAXReader();
        Document document = reader.read(new File("src/main/resources/xml/csdn.xml"));
        Element root = document.getRootElement();
        String docXmlText = document.asXML();
        String rootXmlText = root.asXML();
        Element memberElm = root.element("java");
        String memberXmlText = memberElm.asXML();

        System.out.println(docXmlText);
        System.out.println("----------------------");
        System.out.println(rootXmlText);
        System.out.println("----------------------");
        System.out.println(memberXmlText);
    }
}
